<?php

class Admin_Model_Comments{

	private $commentTbl;
	
	public function __construct(){
		$this->commentTbl = new Admin_Model_DbTable_Comments();
	}
	
	public function selectComment($where=null, $order ='yKienId DESC',$limit =NULL){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$dbSelect = new Zend_Db_Select($dbAdapter);
		
		$dbSelect->from('ykien','*');
		
		if ($where!=NULL) $dbSelect->where($where);
		$dbSelect->order($order);
		if ($limit!=null)$dbSelect->limit($limit);
		
		return $dbSelect; 
	}
	
	public function addComment($hoTen,$email,$chuDe,$noiDung,$ngayYKien){
		$data = array(
			'hoTen'		=>	$hoTen,
			'email'		=>	$email,
			'chuDe'		=>	$chuDe,
			'noiDung'	=>	$noiDung,
			'ngayYKien'	=>	$ngayYKien
		);
		$this->commentTbl->insert($data);
	}
	
	public function deleteComment($yKienId){
		$this->commentTbl->delete("yKienId =".$yKienId);
	}
	
	public function fetchComment($where=NULL){
		if ($where!=NULL){
			return $this->commentTbl->fetchAll($where);
		}else {
			return $this->commentTbl->fetchAll();
		}
	}
	
	

}

